﻿<Window x:Class="WpfClient.MainPageView"
		xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
		xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		xmlns:bing="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF"
		xmlns:local="clr-namespace:WpfClient"

		FontFamily="Segoe UI"
		Background="Black"
		Foreground="White"
		Title="MainPageView" 
		Height="768" 
		Width="1366" WindowState="Maximized" WindowStartupLocation="CenterScreen">

    <Window.Resources>
        <local:EarthquakeEventLocationConverter x:Key="EarthquakeLocationConverter" />
    </Window.Resources>

    <Grid Margin="10 10 10 10">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="400"/>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>

        <Grid Grid.Column="0">
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <ListBox Grid.Row="0" Background="Transparent" Foreground="White"
					FontFamily="Segoe UI"
					FontSize="11pt"
					ItemsSource="{Binding EarthquakeData}"
					SelectedItem="{Binding SelectedEarthquakeEvent, Mode=TwoWay}"    >
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Vertical" Margin="0 0 0 5">
                            <TextBlock Text="{Binding Title}" FontWeight="Bold" FontSize="12pt" />
                            <TextBlock Margin="3 0 0 0">
							<TextBlock.Text>
								<Binding Path="Magnitude" StringFormat="Magnitude: {0}" />
							</TextBlock.Text>
                            </TextBlock>
                            <TextBlock Margin="2 0 0 0">
							<TextBlock.Text>
								<MultiBinding StringFormat="Location: {0}, {1}">
									<Binding Path="Latitude" />
									<Binding Path="Longitude" />
								</MultiBinding>
							</TextBlock.Text>
                            </TextBlock>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

            <TextBlock Foreground="White" FontFamily="Segoe UI" FontSize="10pt" Grid.Row="1" Text="{Binding RefreshMessage}" Margin="0,0,50,0" />
            <Button Command="{Binding SearchCommand}" Content="Search" Grid.Row="1" Width="50" HorizontalAlignment="Right" VerticalAlignment="Center" />
        </Grid>

        <GridSplitter Grid.Column="1" ResizeDirection="Columns" Width="5" 
					  Background="Black"
					  ResizeBehavior="PreviousAndNext" 
					  ShowsPreview="True"/>

        <bing:Map Grid.Column="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
			  CredentialsProvider="As4JvPsy0dULM-13m3Mb-KpNqdBZmclMZkrYHw_UEwTGju22pA-M26RgQ74yqgke" 
				  Center="{Binding MapCenter, Mode=TwoWay}"
				  ZoomLevel="{Binding ZoomLevel, Mode=TwoWay}">
            <bing:MapItemsControl ItemsSource="{Binding EarthquakeData}">
                <bing:MapItemsControl.ItemTemplate>
                    <DataTemplate>
                        <bing:Pushpin 
							Location="{Binding ., Converter={StaticResource ResourceKey=EarthquakeLocationConverter}, Mode=TwoWay}"
							Content="{Binding Magnitude}">
                            <bing:Pushpin.ToolTip>
                                <ToolTip>
                                    <StackPanel>
                                        <TextBlock FontWeight="Bold" Text="{Binding Title}" />
                                        <TextBlock Text="{Binding Magnitude}" />
                                        <TextBlock Text="{Binding Datetime}" />
                                    </StackPanel>
                                </ToolTip>
                            </bing:Pushpin.ToolTip>
                        </bing:Pushpin>
                    </DataTemplate>
                </bing:MapItemsControl.ItemTemplate>
            </bing:MapItemsControl>
        </bing:Map>
    </Grid>
</Window>
